package daily;

import java.util.Scanner;

public class day3_09_4_ac {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		int res = 0;
		for (int i = 2; i <= n; i++) {
			res = (res + k) % i;
		}
		System.out.print(res + 1);
	}
}
